package com.xrit.controller;

import com.xrit.pojo.User;
import com.xrit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("findByUserCount")
    public String findByUserCount(String username, String password, HttpSession session){
        User user = new User();user.setUsername(username);user.setPassword(password);

        Integer byUserCount = userService.findByUserCount(user);
        if(!(null==byUserCount)){
            session.setAttribute("userid",byUserCount);
            return "index";
        }
        return "indexerr";
    }

    @RequestMapping("login")
    public String login(){

        return "index";
    }
    @RequestMapping("findPage")
    @ResponseBody
    public List findPage(){
        ArrayList<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();

        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("id", 1);
        map.put("name", 1);
        map.put("age", 1);
        map.put("sex", 1);
        maps.add(map);
        return maps;
    }
}
